package editor
{
	import UIFree.controls.uif_label;
	import UIFree.uif_ecomponent;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.geom.Rectangle;
	import flash.utils.Timer;

	public class pi_toolbarButton extends uif_ecomponent {
		private var _label: uif_label;
		private var _align: String;
		
		public function pi_toolbarButton(parent: pi_baseToolbar, icon: Class, a_label: String, releaseFunc: Function, a_width: int= 120, align: String = 'left') {
			var inner: Rectangle = parent.getInner();
			super(parent, inner.x, inner.y, a_width, 30, '');
			var _icon: *= addChild(new icon());
			_label 		= new uif_label(this, 27, 0, a_width - 27, 40, 'lbLabel');
			_align 		= align;
			buttonMode 	= true;
			mouseChildren = false;
			
			var timer: Timer = new Timer(500, 1);
			addEvent(TimerEvent.TIMER_COMPLETE, function(e: TimerEvent): void {
				disable = false;	
			}, timer);
			
			
			addEvent(MouseEvent.CLICK, function(e: Event): void {
				releaseFunc(e);
				disable = true;
				timer.start();
			});
			text = a_label;
			(parent as pi_baseToolbar).refreshButtons();
		}
		
		public function get align(): String {
			return _align;
		}
		
		override public function set visible(a_set: Boolean): void {
			super.visible = a_set;
			(parent as pi_baseToolbar).refreshButtons();
		}
		
		public function get text(): String {
			return _label.text;
		}
		
		public function set text(a_text: String): void {
			_label.text = a_text;
		}
	}
}